package org.example.likou150.array;

public class MergeArray {

    public static void main(String[] args) {
        int[] nums1 = new int[]{1,2,3,0,0,0};
        int m = 3;
        int[] nums2 = new int[]{2,5,6};
        int n = 3;

        MergeArray mergeArray=new MergeArray();
        mergeArray.merge(nums1,m,nums2,n);
    }

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int a = m - 1;
        int b = n - 1;
        for (int i = nums1.length - 1; i >= 0; i--) {
            if (a>=0 && (b<0 || nums1[a] > nums2[b]) ) {
                nums1[i] = nums1[a--];
            } else {
                nums1[i] = nums2[b--];
            }
        }


        for (int i = 0; i < nums1.length; i++) {
            System.out.println(nums1[i]);
        }
    }
}
